﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using System.Configuration;
using KeywordDistributeInterface;

namespace KeywordDistributeService
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ServiceHost host = new ServiceHost(typeof(ServiceImpl));

            //参数获取设置的服务地址，如果没有，则保留默认的 127.0.0.1:8888
            string ip = ConfigurationSettings.AppSettings["ServiceIP"];
            int port = 8732;
            string uri = string.Format("net.tcp://{0}:{1}", ip, port);
            NetTcpBinding binding = new NetTcpBinding();
            binding.Security.Mode = SecurityMode.None;
            binding.ReceiveTimeout = TimeSpan.MaxValue;//设置连接自动断开的空闲时长；

            host.AddServiceEndpoint(typeof(IKeywordDistribute), binding, uri);
            //MessageCenter.Instance.ListenerAdded += new EventHandler<MessageListenerEventArgs>(Instance_ListenerAdded);
            //MessageCenter.Instance.ListenerRemoved += new EventHandler<MessageListenerEventArgs>(Instance_ListenerRemoved);
            host.Open();
        }
    }
}
